<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title>中汽中心智慧办公平台</title>
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link rel="stylesheet" href="css/news.css">
    <script src="libs/jquery_1.9.1.min.js"></script>
    <script src="libs/common.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        
        .marginCenter{ width:880px; height: auto; position: absolute;left:0; right:0; margin: auto;}
    </style>
</head>

<body>
    <div class="title" id="title"></div>
    <div class="title" id="description"></div>
    <div class="origin">
        <span id="origin"></span>
        <!-- <span class="time" id="time"></span> -->
    </div>
    <hr style="width: 880px;color: #D8D8D8;margin-top: 15px;" />

    <div class="marginCenter">
        <div id="content"></div>
        <div style="height: 50px;width: 100%"></div>
    </div>

    <script>

        $(document).ready(function () {

            // 获取文章ID
            var articleId = 0;
            var ARTICLE_URL = 'https://portal.catarc.ac.cn/zqy_portalApi/outData/getNewsById?id=';
            var url = window.location.href
            var cs = url.split("?")[1]

            if (cs !== undefined) {
                var tempId = cs.split("=")[1]
                if (tempId !== undefined) {
                    articleId = tempId;
                } else {
                    // 未能正常获取参数
                }
            } else {
                // 未能正常获取参数
            }

            // 获取数据对象
            var title = $('#title');
            var description = $('#description');
            var origin = $('#origin');
            var time = $('#time');
            var content = $('#content')

            // 获取数据
            $.get(ARTICLE_URL + articleId, function (data) {
                title.text(data.data.title);
                if (data.data.description !== '') {
                    description.text(data.data.description);
                }
                origin.text(data.data.author);
                time.text(new Date(data.data.pubTime).Format('yyyy-MM-dd'));
                var html = removeWordXml(data.data.content);
                content.html(html);

                // 改变css 使其适配
                $("font").css({"font":"normal 15px 'Microsoft YaHei'","margin-top":"15px"});
                $("p").css({"font":"normal 15px 'Microsoft YaHei'","margin-top":"15px"});
                $("span").css({"font":"normal 15px 'Microsoft YaHei'","margin-top":"15px"});
                // $("img").css({"margin-top":"15px"});

            });

        });

        function removeWordXml(text) {
            var html = text;
            html = html.replace(/<\/?SPANYES[^>]*>/gi, "");//  Remove  all  SPAN  tags
            // html = html.replace(/<(\w[^>]*)  class=([^|>]*)([^>]*)/gi, "<$1$3");  //  Remove  Class  attributes
            // html = html.replace(/<(\w[^>]*)  style="([^"]*)"([^>]*)/gi, "<$1$3");  //  Remove  Style  attributes
            html = html.replace(/<(\w[^>]*)  lang=([^|>]*)([^>]*)/gi, "<$1$3");//  Remove  Lang  attributes
            html = html.replace(/<\\?\?xml[^>]*>/gi, "");//  Remove  XML  elements  and  declarations
            html = html.replace(/<\/?\w+:[^>]*>/gi, "");//  Remove  Tags  with  XML  namespace  declarations:  <o:p></o:p>
            html = html.replace(/&nbsp;/, "");//  Replace  the  &nbsp;
            html = html.replace(/\n(\n)*( )*(\n)*\n/gi, '\n');
            //  Transform  <P>  to  <DIV>
            // var  re  =  new  RegExp("(<P)([^>]*>.*?)(<//P>)","gi")  ;            //  Different  because  of  a  IE  5.0  error
            //        html = html.replace(re, "<div$2</div>");
            return html;
        }


    </script>
</body>

</html>